﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>编辑轮播图</title>
    <link href="~/Areas/Back/lib/layui/css/layui.css" rel="stylesheet" />
    <script src="~/Areas/Back/lib/layui/layui.js"></script>
</head>
<body>
    <div class="layui-container" style="margin-top:50px;margin-bottom:150px">
        <form class="layui-form" id="addFrom" onsubmit="return false">
            <input type="hidden" id="Id" value="@ViewBag.A.Id" />
            <div class="layui-form-item">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-block">
                    <input type="text" id="Title" class="layui-input" value="@ViewBag.A.Title" placeholder="请输入标题" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">跳转地址</label>
                <div class="layui-input-block">
                    <input type="text" id="ToUrl" class="layui-input" value="@ViewBag.A.ToUrl" placeholder="请输入跳转地址" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">上传图片</label>
                <div class="layui-input-block">
                    <input type="file" id="uplaodImg" name="uplaodImg" />
                    <input type="hidden" id="ImgUrl" value="@ViewBag.A.ImgUrl"/>
                </div>
            </div>
            
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <img id="imgPhoto" class="layui-upload-img" src="~/@ViewBag.A.ImgUrl" style="width:180px; height:140px" />
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="subAdd">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>


        </form>
    </div>
</body>
<script>
    layui.use(['form', 'layedit', 'upload'], function () {
        var form = layui.form;
        var layedit = layui.layedit;
        var layer=layui.layer;
        var upload = layui.upload;
        var $ = layui.$;
        upload.render({
            elem: "#uplaodImg",
            url: "uploadPhoto",
            done: function (res) {
                if (res.success == true) {
                    $("#ImgUrl").val(res.path);
                    $("#imgPhoto").attr("src", "/" + res.path);
                    layer.msg("上传成功");
                } else {
                    layer.msg("上传失败:" + res.message);
                }
            }
        });
        form.on('submit(subAdd)', function () {
            $.ajax({
                url: "EditDel",
                method: "post",
                dataType: "json",
                data: {
                    Id: $("#Id").val(),
                    Title: $("#Title").val(),
                    ImgUrl: $("#ImgUrl").val()
                },
                success: function (res) {
                    if (res.success == true) {
                        layer.msg(res.msg);
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.location.reload();
                    } else {
                        layer.msg(res.msg);
                    }
                }
            });
            return false;
        });
    });
</script>
</html>
